package com.example.tian.mvpforurse;

import android.app.Application;
import android.widget.Button;

import com.androidnetworking.AndroidNetworking;
import com.androidnetworking.interceptors.HttpLoggingInterceptor.Level;
import com.example.tian.mvpforurse.di.component.ApplicationComponent;
import com.example.tian.mvpforurse.di.component.DaggerApplicationComponent;
import com.example.tian.mvpforurse.di.module.ApplicationModule;
import com.example.tian.mvpforurse.utils.AppLogger;


import javax.inject.Inject;

import uk.co.chrisjenx.calligraphy.CalligraphyConfig;

/**
 * @author tian on 2018/11/21
 */
public class MvpApp extends Application {

    private ApplicationComponent mApplicationComponent;

    @Inject
    CalligraphyConfig mCalligraphyConfig;


    @Override
    public void onCreate() {
        super.onCreate();

        mApplicationComponent = DaggerApplicationComponent.builder()
                .applicationModule(new ApplicationModule(this)).build();

        mApplicationComponent.inject(this);

        AppLogger.init();

        AndroidNetworking.initialize(getApplicationContext());
        if (BuildConfig.DEBUG){
            AndroidNetworking.enableLogging(Level.BODY);
        }

        //字体库支持
        CalligraphyConfig.initDefault(mCalligraphyConfig);
    }

    public ApplicationComponent getComponent(){
        return mApplicationComponent;
    }

    /**
     * Needed to replace the component with a test specific one
     */
    public void setComponent(ApplicationComponent applicationComponent){
        mApplicationComponent = applicationComponent;
    }
}
